/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.company.Logic;

import com.company.builders.BuilderCurve;
import com.company.primitivies.Curve;
import com.company.primitivies.Ellipse;
import com.company.primitivies.Point2d;
import com.company.lineup.LineUp;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 *
 * @author admin
 */
public class Measure {

    private Ellipse ell;

    public Measure(double a, double b) {
        ell = new Ellipse(a, b);
    }

    public Map<Point2d, Double> stretch(double h) {
        Map<Point2d, Double> result = new LinkedHashMap<>();
        for (Point2d point : ell.generateListPoint(h)) {
            Curve curve = new Curve(ell, point);
            BuilderCurve builder = new BuilderCurve(curve);
            double z = LineUp.measure(builder.negCase(h)) + LineUp.measure(builder.posCase(h));
            result.put(point, z);
        }
        writeDump(result);
        return result;
    }

    public void writeDump(Map<Point2d, Double> map) {
        try (PrintWriter out = new PrintWriter(new File("src/main/resources/dump.txt").getAbsoluteFile())) {

            for (Map.Entry<Point2d, Double> entry
                    : map.entrySet()) {

                Point2d key = entry.getKey();
                double value = entry.getValue();
                System.out.println(key.getX() + " " + key.getY() + " " + value);
                out.println(key.getX() + " " + key.getY() + " " + value);

            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
